<?php 
	// Get the logged in user information.
	$user = $this->requestAction('users/login'); 
	
?>

<div id="navigation" class="column">
<p>You are currently logged in as 
	<span style="color:blue;"><?php echo $user['User']['username'] ?></span> 
	if this is in error please 
	<?php echo $this->Html->link('Logout', '/users/logout');?>
</p>

<?php

	if(isset($this->data['Application']))
		$app = $this->data;
		
	if (isset($app_id) && $app_id) {
		$app = $this->requestAction("applications/view/{$app_id}");
	}
	
	switch($user['User']['group_id']) {
	
		case 1: //Administrators
			
			if (!isset($app) || !$app) {
				echo "<p>You have not selected an application to edit.</p>";
				echo '<ul><li><form accept-charset="utf-8" method="post" action="/Applications/adminSearch"> ';
				echo '<label for="term">Search:</label><br />';
				echo '<input id="term" size="15" type="text" name="data[email]" placeholder="Enter email"/>';
				echo ' <input type="submit" value="Go" />';
				echo '</form></li></ul>';
				echo '<ul><li>' . $this->Html->link('Activate Application', array('controller' => 'users', 'action' => 'activate')) . '</li>';
				echo '<li>' . $this->Html->link('Edit Application Content', array('controller' => 'AppInformationElements')) . '</li>';
				echo '<li>&nbsp</li>';
				echo '<li>' . $this->Html->link('Upload Applicants', array('controller' => 'Users', 'action' => 'upload')) . '</li>';
				echo '<li>' . $this->Html->link('Create User', array('controller' => 'Users', 'action' => 'add')) . '</li>';
				echo '<li>' . $this->Html->link('Home', array('controller' => 'Applications', 'action' => 'index')) . '</li>';
				echo '<li>&nbsp</li>';
				echo '<li>' . $this->Html->link('List Users', array('controller' => 'Users',
																														'action' => 'index')) . '</li>';
				echo '<li>' . $this->Html->link('List Groups', array('controller' => 'Groups',
																														 'action' => 'index')) . '</li>';
				echo '<li>' . $this->Html->link('Send Reference Emails', array('controller' => 'References',
																														 'action' => 'adminEmail')) . '</li>';																										
				echo '<li>' . $this->Html->link('Change account info', array('controller' => 'Users', 'action' => 'edit' , $user['User']['id'])) . '</li>'; 
				echo '<li>' . $this->Html->link('Logout', array('controller' => 'Users', 'action' => 'logout')) . '</li></ul>';
				echo '<p>Reporting</p>';
				echo '<ul><li>' . $this->Html->link('Search', array('controller' => 'Applications', 'action' => 'search')) . '</li>';
				echo '<li>' . $this->Html->link('Export to Excel', array('controller' => 'Applications', 'action' => 'export')) . '</li></ul>';
				break;
				
			} else { //add admin info and links then give appnav.
				echo "<p>You are currently viewing Application number 
							<span style=\"color:blue;\">{$app['Application']['id']}</span>, the application of 
							<span style=\"color:blue;\">{$app['Application']['firstname']} 
							{$app['Application']['lastname']}</span>.</p>";
				echo '<ul><li>' 
						 . $this->Html->link('Delete User', 
																	array('controller' => 'Users', 'action' => 'delete', $app['User']['id']), 
																				null, 'Are you sure you want to delete user '
						 													. "{$app['Application']['firstname']}" 
						 													. " {$app['Application']['lastname']}") . '</li>';
				echo '<li>' . $this->Html->link('Change Status Messages for this User', 
																				array('controller' => 'Applications',
																							'action' => 'modifyStatus',
																							$app['Application']['id'])) . '</li>';
				echo '<li>' . $this->Html->link('Upload Paper Recommendation', 
																				array('controller' => 'References',
																							'action' => 'adminComplete',
																							$app['Application']['id'])) . '</li>';
				echo '<li>' . $this->Html->link('Add GRE and TOEFL scores', 
																				array('controller' => 'Scores', 
																							'action' => 'edit', 
																							$app['Score']['id'])) . '</li>';
				echo '<li>' . $this->Html->link('Admin Home', array('controller' => 'Applications', 
																														'action' => 'index')) . '</li></ul>';
				
			}
		
		case 2: //Applicant
			if (isset($app) && $app) {	
				echo "<dl><dt>" . $this->Html->link('Change Email address or password',
																			array('controller' => 'Users', 
																						'action' => 'edit', 
																						$app['User']['id'])) . '</dt>';
				echo "<dt>" . renderStatus($app['Application']['pif_stat'], $this->Html) 
							. ' ' . $this->Html->link('Personal Info', 
																	array('controller' => 'Applications', 
																				'action' => 'edit',
																				$app['Application']['id']), 
																	array('alt' => $app['Application']['pif_msg'])) 
							. '</dt><dd><p>' . $app['Application']['pif_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['studyinterest_stat'], $this->Html) 
							. ' ' . $this->Html->link('Study/Research Interests', 
																	array('controller' => 'Studyinterests',
																				'action' => 'edit', $app['Studyinterest']['id']), 
																	array('alt' => $app['Application']['studyinterest_msg'])) 
							. '</dt><dd><p>' . $app['Application']['studyinterest_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['edhistory_stat'], $this->Html) 
							. ' ' . $this->Html->link('Educational History', 
																	array('controller' => 'Schools',
																				'action' => 'index',
																				$app['Application']['id']), 
																	array('alt' => $app['Application']['edhistory_msg'])) 
							. '</dt><dd><p>' . $app['Application']['edhistory_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['courses_stat'], $this->Html) 
							. ' ' . $this->Html->link('Courses', 
																	array('controller' => 'Courselists',
																				'action' => 'edit', 
																				$app['Courselist']['id']), 
																	array('alt' => $app['Application']['courses_msg'])) 
							. '</dt><dd><p>' . $app['Application']['courses_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['references_stat'], $this->Html) 
							. ' ' . $this->Html->link('References', 
																	array('controller' => 'References',
																				'action' => 'index',
																				$app['Application']['id']), 
																	array('alt' => $app['Application']['references_msg'])) 
							. '</dt><dd><p>' . $app['Application']['references_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['depth_stat'], $this->Html) 
							. ' ' . $this->Html->link('Additional Qualifications', 
																	array('controller' => 'Attachments',
																				'action' => 'add', 
																				$app['Application']['id'],
																				'cv'), 
																	array('alt' => $app['Application']['depth_msg'])) 
							. '</dt><dd><p>' . $app['Application']['depth_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['pstatement_stat'], $this->Html) 
							. ' ' . $this->Html->link('Personal Statement', 
																	array('controller' => 'Attachments',
																				'action' => 'add',
																				$app['Application']['id'],
																				'ps'), 
																	array('alt' => "{$app['Application']['pstatement_msg']}")) 
							. '</dt><dd><p>' . $app['Application']['pstatement_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['wsample_stat'], $this->Html) 
				      . ' ' . $this->Html->link('Writing Sample', 
				      										array('controller' => 'Attachments',
				      													'action' => 'add',
				      													$app['Application']['id'],
				      													'ws'), 
				      										array('alt' => "{$app['Application']['wsample_msg']}")) 
				      . '</dt><dd><p>' . $app['Application']['wsample_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['transcripts_stat'], $this->Html) 
							. ' ' . $this->Html->link('Transcripts', 
																	array('controller' => 'Applications',
																				'action' => 'transcripts',
																				$app['Application']['id']), 
																	array('alt' => $app['Application']['transcripts_msg'])) 
							. '</dt><dd><p>' . $app['Application']['transcripts_msg'] . '</p></dd>';
				echo "<dt>" . renderStatus($app['Application']['gre_stat'], $this->Html) 
							. ' ' . $this->Html->link('GRE Scores', 
																	array('controller' => 'Applications',
																				'action' => 'gre',
																				$app['Application']['id']), 
																	array('alt' => $app['Application']['gre_msg'])) 
							. '</dt><dd><p>' . $app['Application']['gre_msg'] . '</p></dd>';
				if (isset($app['Application']['toefl_req']) && $app['Application']['toefl_req']) {
					echo "<dt>" . renderStatus($app['Application']['toefl_stat'], $this->Html) 
								. ' ' . $this->Html->link('TOEFL Score', 
																		array('controller' => 'Applications',
																					'action' => 'toefl',
																					$app['Application']['id']), 
																		array('alt' => $app['Application']['toefl_msg'])) 
							  . '</dt><dd><p>' . $app['Application']['toefl_msg'] . '</p></dd>';
				}
				echo '<dt>' . $this->Html->link('My Welcome Page', 
																		array('controller' => 'Applications',
																					'action' => 'view',
																					$app['Application']['id'])) . '</dt>';
				echo '<dt>' . $this->Html->link('Logout', 
																				array('controller' => 'Users',
																							'action' => 'logout')) . '</dt></dl>';
				
			} else {
				echo "<p>There was an error, please" . $this->Html->link('Logout', 
																														array('controller' =>'Users',
																																	'action' => 'logout')) 
						 . " and log back in."
						 . " If you continue to see this message contact gradsec@psych.uoregon.edu.</p>";
			}
			break;
		
		case 3:
		case 4:
		case 5:
			echo "<dl><dt>" 
					 . $this->Html->link('Change Email address or password', 
												 array('controller' => 'Users',
												 			 'action' => 'edit',
												 			 $user['User']['id'])) . '</dt>';
			echo '<dt>' . $this->Html->link('Logout', 
																array('controller' => 'Users',
																			'action' => 'logout')) .'</dt></dl>';
			echo '<p>Reporting</p>';
				echo '<ul><li>' . $this->Html->link('Search', 
																				array('controller' => 'Applications',
																							'action' => 'search')) . '</li></ul>';
			break;
	}
	
function renderStatus($status, $html) {
	switch ($status) {
		case 'red': 
			return $html->image('redlight_yb.jpg', array('alt' => 'No Submission'));
			break;
		case 'yellow':
			return $html->image('yellowlight_yb.jpg', array('alt' => 'Incomplete'));
			break;
		case 'green':
			return $html->image('greenlight_yb.jpg', array('alt' => 'Complete'));
			break;
	}
}
	
?>
</div>
